<template>
	<view class="height-100 bg-gray overflow-hidden">
		<view class="padding">
			<view class="bd-img flex-direction-row justify-between">
				<view class="flex-direction-row padding-xl">
					<image :src="userinfo.avatar || '../../static/images/user.png'" class="cu-goods round" mode="aspectFit"></image>
					<view class="margin-left">
						<text class="text-lg color-white">{{userinfo.doctorName}}</text>
						<view class="radius-sl bg-tag flex-direction-row justify-center align-center margin-top-xsm">
							<text class="text-sm color-white-q">{{userinfo.department}}</text>
						</view>
					</view>
				</view>
				<view class="margin-top">
					<view class="radius bg-white-qq flex-direction-row align-center padding-tb-xs padding-left-xs">
						<text class="text-xl iconfont color-df">&#xe631;</text>
						<text class="text-df color-df margin-left-xs margin-right-xl">{{userinfo.title}}</text>
					</view>
				</view>
			</view>
			<view class="bg-white radius-xl margin-top">
				<view class="flex-direction-row align-center padding border-top" @click="logout">
					<text class="text-xl iconfont color-df">&#xe613;</text>
					<text class="text-df margin-lr flex-sub">退出登录</text>
					<text class="text-df iconfont color-gray">&#xe61f;</text>
				</view>
			</view>
		</view>
		<tab-bars :tabbarList='tabbarList' :selected="tabbarList.length - 1"/>
	</view>
</template>

<script>
	import {
		// getLoginCheck,
	} from "@/common/user.js"
	// import tabBars from '@/components/TabBar.vue'; // 引入 tabBar 组件
	export default {
		components:{
			// tabBars
		},
		onLoad() {
			this.tabbarList = uni.$setupTabBar();
			if(uni.getStorageSync('token')){
			}
			uni.$on('updateUser', data => {
				this.userinfo = uni.getStorageSync('userinfo');
			});
		},
		onUnload() {
			uni.$off('updateUser');
		},
		data() {
			return {
				userinfo:{},
				tabbarList:[],
				userType:uni.getStorageSync('userType')
			}
		},
		methods: {
			// 获取用户信息|
			async getDoctorInfos(id){
				const res = await uni.$request.get('/doctorApi/'+id, {});
				console.log('getDoctorInfos res: ', res.data);
				if (res.code === 200) {
					
				} else {
					// uni.showModal({
					// 	title: '提示',
					// 	content: '数据查询失败',
					// 	showCancel: false
					// });
				}
			},
			// 退出登录
			logout() {
				uni.showModal({
					title: '提示',
					content: '退出登录吗？',
					cancelText: '取消',
					confirmText: '退出',
					success: res => {
						if (res.confirm) {
							uni.removeStorageSync('userinfo')
							// uni.removeStorageSync('token')
							uni.setStorageSync('token', '');
							console.log(uni.getStorageSync('userinfo'));
							// uni.reLaunch({
							// 	url:"/pages/index/index"
							// })
							uni.$emit('loginStatusChange', {
								login: 'out'
							});
							// uni.navigateBack();
							// 跳转登录页
							uni.redirectTo({
								url: '/pages/login/login'
							});
						} else if (res.cancel) {
							console.log('用户点击取消');
						}
					}
				});
			},
			async getJurisdiction(){
			 //    let data = {
				// 	phone: this.userinfo.mobile,
				// 	type: this.userType == 1 ? 0 : 1,//如果是医师1切换到0，需要拿员工0去判定权限，没有权限则提醒
				// }
				// let res = await getLoginCheck(data);
				// if(res.code!==200){
				// 	return uni.showModal({
				// 		content: res.msg,
				// 		showCancel: false
				// 	});
				// }  
			},
			checkIdentity(){
				let code =  this.userType;
				uni.showModal({
					title: '提示',
					content: code ==1 ? '是否切换到员工端?':'是否切换到医师端?',
					cancelText: '取消',
					confirmText: '确认',
					success: res => {
						if (res.confirm) {
							this.getJurisdiction()
							// 跳转登录页
							uni.setStorageSync('baseTabBar', uni.$setupTabBar())
							uni.redirectTo({
								url: code == 1 ? "/pages/index/staffIndex" : "/pages/index/index"
							});
						} else if (res.cancel) {
							console.log('用户点击取消');
						}
					}
				});
			}
		}
	}
</script>

<style scoped>
	.bd-img {
		width: 690rpx;
		height: 219rpx;
		background-image: url('../../static/images/mine_card.png');
		background-size: 100% 100%;
		background-repeat: no-repeat;
	}
	.bg-tag{
		width: 96rpx;
		height: 37rpx;
		background: rgba(255,255,255,0.1);
		border: 2rpx solid rgba(255,255,255,0.2);
	}
</style>